package fun.hijklmn.magic.resource.server.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @Description
 * @Author fs
 * @Date 2021/5/17 14:54
 * @Version 0.0.1-SNAPSHOT
 **/
@Slf4j
@Configuration
public class ResourceWebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private ResourceProperties resourceProperties;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("----------->本地文件映射，访问前缀：{}，本地地址：{}", resourceProperties.getReqPrefix(), resourceProperties.getLocalDir());
        registry.addResourceHandler(resourceProperties.getReqPrefix()).addResourceLocations(resourceProperties.getLocalDir());
        super.addResourceHandlers(registry);
    }

}
